package com.hgm.travelapp.fragment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import androidx.fragment.app.DialogFragment
import androidx.viewbinding.ViewBinding
import com.hgm.travelapp.R

/**
 * @author    HGM
 * @version   1.0
 */
class DeleteDialog : DialogFragment() {

      override fun onCreateView(
            inflater: LayoutInflater,
            container: ViewGroup?,
            savedInstanceState: Bundle?
      ): View? {
            //加载试图
            val view = inflater.inflate(R.layout.delete_dialog_fragment, container, false)
            //绑定控件
            val cancel = view.findViewById<Button>(R.id.btn_cancel)
            val sure = view.findViewById<Button>(R.id.btn_sure)
            //点击事件
            cancel.setOnClickListener {
                  dismiss()
            }
            sure.setOnClickListener {
                  dismiss()
                  //TODO 删除业务

            }
            return view
      }


      override fun onStart() {
            super.onStart()
            if (dialog != null) {
                  val metrics = resources.displayMetrics
                  //宽度设为屏幕宽度的90%
                  dialog!!.window?.setLayout(
                        (metrics.widthPixels * 0.9).toInt(),
                        ViewGroup.LayoutParams.WRAP_CONTENT
                  )
            }
      }
}